﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ManageSystem后台管理系统</title>
    <!-- bootstrap 3.0.2 -->
    <link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="/resource/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/resource/js/jQueryMessage/css/message.skin.css" />
	<style>
		.stu_left{
			float: left;
			width: 300px;
		}
		.stu_center{
			float: left;
			width: 300px;
		}
		.stu_right{
			float: left;
			width: 300px;
		}
		select{
			width: 250px;
		}
	</style>
</head>

<body>
	<div class="row">
	    <div class="col-md-12">
	    	<h1 class="panel-heading">新增教师</h1>
	        <!--breadcrumbs start -->
	        <ul class="breadcrumb">
				<li><a href="/index/toIndex"><i class="fa fa-home"></i> 首页</a></li>
				<li class="active">新增教师</li>
			</ul>
	        <!--breadcrumbs end -->
	    </div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<section class="panel">
				<div class="panel-body">
					<form class="col s12" id="form1" enctype="multipart/form-data" th:action="@{/stu/teacher/add}" onsubmit="return validateForm();" method="post">
						<div class="stu_left">
							<div class="form-group form-control-medium">
								<label for="collegeId">学院：</label>
								<input id="collegeId" name="collegeId" type="text"  class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="teacherId">工号(1001-9999)：</label>
								<input id="teacherId" name="teacherId" type="number" min="1000" max="9999" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="name">姓名：</label>
								<input id="name" name="name" type="text" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="engName">英文名：</label>
								<input id="engName" name="engName" type="text" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="nation">民族：</label>
								<input id="nation" name="nation" type="text" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="birth">出生日期：</label>
								<input id="birth" name="birth" type="date" class="form-control"/>
							</div>
						</div>
						<div class="stu_center">
							<div class="form-group form-control-medium">
								<label for="age">年龄(22-60)：</label>
								<input id="age" name="age" type="number" min="22" max="60" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="address">现居住地：</label>
								<input id="address" name="address" type="text" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
								<label for="phone">电话：</label>
								<input id="phone" name="phone" type="text" class="form-control"/>
							</div>
							<div class="form-group form-control-medium">
							<label for="status">状态：</label>
							<select class="form-group" id="status" name="status">
								<option value="1" selected>启用</option>
								<option value="0">禁用</option>
							</select>
							</div>
							<div class="form-group form-control-medium">
							<label for="gender">性别：</label>
							<select class="form-group" id="gender" name="gender">
								<option value="1" selected>男</option>
								<option value="0">女</option>
							</select>
							</div>
							<div class="form-group form-control-medium">
							<label for="rank">职称：</label>
							<select class="form-group" id="rank" name="rank">
								<option value="1" selected>教师</option>
								<option value="2">副教授</option>
								<option value="3">教授</option>
							</select>
							</div>
						</div>
						<div class="stu_right">
							<div class="form-group form-control-medium">
							<label for="marital">婚姻状况：</label>
							<select class="form-group" id="marital" name="marital">
								<option value="0" selected>未婚</option>
								<option value="1">已婚</option>
							</select>
							</div>
							<input id="createdBy" name="createdBy" type="hidden" class="form-control" />

							<div class="form-btn-group-left">
			            		<button type="submit" class="btn btn-info">保存</button>
								<button type="button" class="btn btn-info" id="back"><a href="/stu/teacher/list">返回</a></button>
			            	</div>
						</div>
					</form>
				</div>
			</section>
		</div>
	</div>
	<script src="/resource/js/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/resource/js/jQueryMessage/js/jquery.plugin.message.js"></script>
    
    <script type="text/javascript" th:inline="javascript">
        $("#teacherId").focusout(function() {
            var teacherId = $("#teacherId").val();
            if(teacherId != null && teacherId != ''){
                checkTeacherId(teacherId);
            }
        });

        function checkTeacherId(teacherId){
            $.ajax({
                url : "/stu/teacher/isTeacher?teacherId="+teacherId,
                contentType : 'application/json',
                type : "GET",
                dataType : "JSON",
                success : function(result) {
                    console.log(result);
                    if(result.success){
                        $("body").MessageBox({
                            type: 'success',
                            message:result.info,
                            timeout:3000,
                            callbak:null
                        });

                    }else{
                        $("body").MessageBox({
                            type: 'error',
                            message:result.info,
                            timeout:3000,
                            callbak:null
                        });
                        alert(result.info)
                    }
                }
            });
        }


	   	/* 保存方法 */
	    function validateForm(){
			var teacherId = $("#teacherId").val();
			var name = $("#name").val();
			var engName = $("#engName").val();
			var phone = $("#phone").val();
			var birth = $('#birth').val();

			if(teacherId == null || teacherId==''){
				$("body").MessageBox({
					type: 'error',
					message:'工号不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(name == null || name ==''){
				$("body").MessageBox({
					type: 'error',
					message:'姓名不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(engName == null || engName==''){
				$("body").MessageBox({
					type: 'error',
					message:'英文名不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(phone == null || phone==''){
				$("body").MessageBox({
					type: 'error',
					message:'电话不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(birth == null || birth==''){
				$("body").MessageBox({
					type: 'error',
					message:'出生日期不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
            return true;
	    }

		//获取当前登录的用户
		var userStr = sessionStorage.getItem("douglas");
		if(userStr == null || userStr == "" || userStr == "undefined"){
			window.location.href = "/stu/user/toLogin";
		}else{
			var user = JSON.parse(userStr);
			$("#createdBy").val(user.realname);
		}
    </script>
</body>
</html>
